﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;

using System.Data.SqlTypes;
using System.Data;

using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mysqlx;

namespace 十站联竞职员平台
{
    public class Database
    {
        string DB_name = "test";
        string DB_host = "test";
        string DB_port = "test";
        string DB_user = "test";
        string DB_password = "test";
        MySqlConnection conn;
        public Database() {
        
            //初始化MySQL
        string DB_Connect = DB_host + "," + DB_name + "," + DB_user + "," + DB_password;
            
            
            

            try
            {
                this.conn = new MySqlConnection(DB_Connect);

            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void connection()
        {
            try
            {
                this.conn.Open();
                
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }



        public bool Login(string username, string password)
        {
            try
            {
                string sql = string.Format("select * from user where userName='{0}'", username);
                MySqlCommand command = new MySqlCommand(sql, this.conn);
                MySqlDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    string psw = reader["password"].ToString();
                    if (psw == password)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }


                }
            }catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return false;
        }

        

        //查询参赛作品
        public string[] Check_Work() {
            string cmdShowEmployees = "SELECT * FROM Work;";

            MySqlCommand command = new MySqlCommand(cmdShowEmployees, this.conn);
            MySqlDataReader reader = command.ExecuteReader();

            return reader.Read().ToString().Split(new char[] { ',' });
                
        }
        //查询违规名单
        public string[] Check_WeiGui()
        {
            string cmdShowEmployees = "SELECT * FROM ;";
            MySqlCommand command = new MySqlCommand(cmdShowEmployees, this.conn);
            MySqlDataReader reader = command.ExecuteReader();

            return reader.Read().ToString().Split(new char[] { ',' });
        }
    }
}
